//
//  BOBOTip.m
//  Tip
//
//  Created by 亿拓普 on 16/12/7.
//  Copyright © 2016年 qiqi. All rights reserved.
//
#define BOBOW [UIScreen mainScreen].bounds.size.width
#define BOBOH [UIScreen mainScreen].bounds.size.height

#import "BOBOTip.h"

@interface BOBOTip()
@property (nonatomic, weak)UILabel *tipLabel;

@end

@implementation BOBOTip

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];// 先调用父类的initWithFrame方法
    if (self) {
        
        self.frame = CGRectMake(0, -84, BOBOW, 84);
        self.backgroundColor = [UIColor colorWithRed:20/255.0 green:200/255.0 blue:255/255.0 alpha:1.0];
        [[UIApplication sharedApplication].keyWindow addSubview:self];
        
        UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, BOBOW, 44)];
        tipLabel.font = [UIFont systemFontOfSize:16];
        [self addSubview:tipLabel];
        self.tipLabel = tipLabel;
        tipLabel.textAlignment = NSTextAlignmentCenter;
        tipLabel.textColor = [UIColor whiteColor];

    }
    return self;
}

+ (void)tipViewWithTipName:(NSString *)tipName
{
    BOBOTip *tip = [BOBOTip new];
    
    [UIView animateWithDuration:0.5 delay:0.0 usingSpringWithDamping:0.7 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        CGRect tipF = tip.frame;
        tipF.origin.y = -20;
        tip.frame = tipF;
    } completion:nil];
    
    // Duration 动画时长   delay 动画延迟
    [UIView animateWithDuration:0.5 delay:2.5 usingSpringWithDamping:0.7 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        CGRect tipF = tip.frame;
        tipF.origin.y = -84;
        tip.frame = tipF;
    } completion:^(BOOL finished) {
        [tip removeFromSuperview];
    }];
    
    tip.tipLabel.text = tipName;
    
    CGRect tipF = tip.frame;
    tip.frame = tipF;
    NSLog(@"%f", tip.origin.y);
}





















@end
